<?php

class Jd_pay_log_model extends MY_Model {


    public function __construct()
    {
        $this->modelename='Jd_pay_log_model';
        $this->tablename='pay_log';
        parent::__construct();
    }



    public function addpaylog($array){
        $array['addtime']=time();
        return  $r= $this->add($this->tablename,$array);
    }

    public function getallmoney($type=2,$remarks='',$webid="",$date1="",$date2=""){
        if($webid==""){
            $webid=$this->web_id;
        }
        if(!$date1){
            $date1 = $this->input->post('date1')? $this->input->post('date1'):date('Y-m-d');
        }
        if(!$date2){
            $date2 = $this->input->post('date2')? $this->input->post('date2'):date('Y-m-d 23:59:59');
        }
        $data1=date('Y-m-d H:i:s',strtotime($date1));
        $data1=strtotime($data1);
        $data2=date('Y-m-d H:i:s',strtotime($date2));
        $data2=strtotime($data2);
        $where="select sum(p1.money) as 'allmoney',count(DISTINCT(p1.user_id)) as 'num' ,sum(p1.gold) as 'allgold'  from jd_pay_log as p1
left join  jd_users as p2 on p1.user_id=p2.id   
   where  p2.iskefu=0 AND   p2.password!='qwer1234'  AND  user_type=2  AND `type`=$type  ";
        $where.=" AND addtime>$data1 AND  addtime<$data2";
        if($webid){
            $where.=" AND  p1.webid=$webid";
        }
        if($remarks){
            $where.="  AND  remarks='$remarks'";
        }
        return  $this->GetBySql($where,0);
    }

    public function checkFuli($user_id){
        $date=date('Y-m-d');
        $firstday = date('Y-m-01 00:00:00', strtotime($date));
        $lastday = date('Y-m-d 23:59:59', strtotime("$firstday +1 month -1 day"));
        $firstday=strtotime($firstday);
        $lastday=strtotime($lastday);
        $sql="select 1  from  jd_pay_log where addtime>=$firstday AND addtime<$lastday AND user_id=$user_id AND remarks='VIP每月奖励'";
        return  $this->GetBySql($sql,0);
}









}
